<template>
  <div>
    <nav-bar>
      <div slot="left" class="back" @click="backClick">
        <img src="@/assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center" class="title">
        <div v-for="(item, index) in titles" :class="{ active: currentIndex === index }" class="title-item"
          @click="titleClick(index)" :key="item">
          <span>{{ item }}</span>
        </div>
      </div>
      <div slot="right">...</div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from '@/components/common/navbar/NavBar.vue'

export default {
  name: 'DetailNavBar',
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ['商品', '参数', '评论', '推荐'],
      currentIndex: 0,
    }
  },
  methods: {
    // 活跃的标签
    titleClick(index) {
      // 更改index
      // 发送子传父的自定义事件
      this.currentIndex = index
      this.$emit('titleClick', index)
    },
    backClick() {
      // 页面返回
      this.$router.back()
    }
  }
}
</script>

<style scoped>
.title {
  display: flex;
}

.title-item {
  flex: 1;
  font-size: 16px;
}

.active {
  color: var(--color-high-text);
}

.active span {
  padding: 5px;
  border-bottom: 2px solid var(--color-tint);
}

.back img {
  margin-top: 14px;
}
</style>
